package com.lee.dhsg.dao.provider;

import java.util.Map;

import org.apache.ibatis.jdbc.SQL;

import com.lee.dhsg.domain.Teacher;

/**
 * @author Jun
 */
public class TeacherSqlProvider {
    /**
     * 动态查询教师
     * @param params
     * @return
     */
    public String selectWhitParam(Map<String, Object> params) {
        return new SQL() {
            {
                SELECT("*");
                FROM("teacher");
                if (params.get("teacher") != null) {
                    Teacher teacher = (Teacher) params.get("teacher");
                    if (teacher.getUsername() != null && !teacher.getUsername().equals("")) {
                        WHERE("username LIKE CONCAT ('%',#{teacher.username},'%') ");
                    }
                    if (teacher.getRealname() != null && !teacher.getRealname().equals("")) {
                        WHERE("realname LIKE CONCAT ('%',#{teacher.realname},'%') ");
                    }
                    if (teacher.getiDCardNum() != null && !teacher.getiDCardNum().equals("")) {
                        WHERE("IDCardNum LIKE CONCAT('%',#{teacher.iDCardNum},'%')");
                    }
                    if (teacher.getSex() != null && !teacher.getSex().equals("")) {
                        WHERE("sex=#{teacher.sex}");
                    }
                    if (teacher.getRealnameStatus() != null && !teacher.getRealnameStatus().equals("")) {
                        WHERE("realnameStatus=#{teacher.realnameStatus}");
                    }
                    if (teacher.getCheckStatus() != null && !teacher.getCheckStatus().equals("")) {
                        WHERE("checkStatus=#{teacher.checkStatus}");
                    }
                    if (teacher.getTuijian() != null && !teacher.getTuijian().equals("")) {
                        WHERE("tuijian=#{teacher.tuijian}");
                    }
                }
            }
        }.toString();
    }

    /**
     * 动态插入教师
     *
     * @param teacher
     */
    public String insertTeacher(Teacher teacher) {
        return new SQL() {
            {
                INSERT_INTO("teacher");
                if (teacher.getUsername() != null && !teacher.getUsername().equals("")) {
                    VALUES("username", "#{username}");
                }
                if (teacher.getPassword() != null && !teacher.getPassword().equals("")) {
                    VALUES("password", "#{password}");
                }
                if (teacher.getRealname() != null && !teacher.getRealname().equals("")) {
                    VALUES("realname", "#{realname}");
                }
                if (teacher.getiDCardNum() != null && !teacher.getiDCardNum().equals("")) {
                    VALUES("IDCardNum", "#{iDCardNum}");
                }
                if (teacher.getiDCardImg01() != null && !teacher.getiDCardImg01().equals("")) {
                    VALUES("IDCardImg01", "#{iDCardImg01}");
                }
                if (teacher.getiDCardImg02() != null && !teacher.getiDCardImg02().equals("")) {
                    VALUES("IDCardImg02", "#{iDCardImg02}");
                }
                if (teacher.getiDCardVideo() != null && !teacher.getiDCardVideo().equals("")) {
                    VALUES("IDCardVideo", "#{iDCardVideo}");
                }
                if (teacher.getSex() != null && !teacher.getSex().equals("")) {
                    VALUES("sex", "#{sex}");
                }
                if (teacher.getIcon() != null && !teacher.getIcon().equals("")) {
                    VALUES("icon", "#{icon}");
                }
                if (teacher.getSignatrue() != null && !teacher.getSignatrue().equals("")) {
                    VALUES("signatrue", "#{signatrue}");
                }
                if (teacher.getDescription() != null && !teacher.getDescription().equals("")) {
                    VALUES("description", "#{description}");
                }
                if (teacher.getTel() != null && !teacher.getTel().equals("")) {
                    VALUES("tel", "#{tel}");
                }
                if (teacher.getEmail() != null && !teacher.getEmail().equals("")) {
                    VALUES("email", "#{email}");
                }
                if (teacher.getLastlogin() != null && !teacher.getLastlogin().equals("")) {
                    VALUES("lastlogin", "#{lastlogin}");
                }
                if (teacher.getRealnameStatus() != null && !teacher.getRealnameStatus().equals("")) {
                    VALUES("realnameStatus", "#{realnameStatus}");
                }
                if (teacher.getCheckStatus() != null && !teacher.getCheckStatus().equals("")) {
                    VALUES("checkStatus", "#{checkStatus}");
                }
            }
        }.toString();
    }

    /**
     * 动态更新教师
     * @param teacher
     * @return
     */
    public String updateTeacher(Teacher teacher) {
        return new SQL() {
            {
                UPDATE("teacher");
                if (teacher.getRealname() != null) {
                    SET("realname=#{realname}");
                }
                if (teacher.getiDCardNum() != null) {
                    SET("IDCardNum=#{iDCardNum}");
                }
                if (teacher.getiDCardImg01() != null) {
                    SET("IDCardImg01=#{iDCardImg01}");
                }
                if (teacher.getiDCardImg02() != null) {
                    SET("IDCardImg02=#{iDCardImg02}");
                }
                if (teacher.getiDCardVideo() != null) {
                    SET("IDCardVideo=#{iDCardVideo}");
                }
                if (teacher.getUsername() != null) {
                    SET("username=#{username}");
                }
                if (teacher.getPassword() != null) {
                    SET("password=#{password}");
                }
                if (teacher.getSex() != null) {
                    SET("sex=#{sex}");
                }
                if (teacher.getIcon() != null) {
                    SET("icon=#{icon}");
                }
                if (teacher.getSignatrue() != null) {
                    SET("signatrue=#{signatrue}");
                }
                if (teacher.getDescription() != null) {
                    SET("description=#{description}");
                }
                if (teacher.getTel() != null) {
                    SET("tel=#{tel}");
                }
                if (teacher.getEmail() != null) {
                    SET("email=#{email}");
                }
                if (teacher.getLastlogin() != null) {
                    SET("lastlogin=#{lastlogin}");
                }
                if (teacher.getRealnameStatus() != null) {
                    SET("realnameStatus=#{realnameStatus}");
                }
                if (teacher.getCheckStatus() != null) {
                    SET("checkStatus=#{checkStatus}");
                }
                WHERE("tid=#{tid}");
            }
        }.toString();
    }
}
